<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				个人中心
			</block>
		</cu-custom>
		<a-lists :keys="keys" :value="info">
			<template #portraitPhoto="{row,index,value}">
				<view class="image-box">
					<text class="image iconfont icon-jia"></text>
					<image class="image" :src="'data:image/png;base64,'+ value" @click='setPhoto(value)'></image>
				</view>
			</template>
		</a-lists>
		<view class="out">
			<a-button class="btn" @click="out">解除绑定</a-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keys: [
					{
						lable:'人像照片',
						key:'photo',
						slot:'portraitPhoto'
					},
					{
						lable: '姓名',
						key: "name"
					},
					{
						lable: '姓别',
						key: "sex"
					}, {
						lable: '学号',
						key: "stuNumber"
					}, {
						lable: '班级',
						key: "bjname"
					}, {
						lable: '电话',
						key: "telephone"
					}, {
						lable: '身份证',
						key: "idCard"
					}
				]
			}
		},
		computed: {
			info() {
				const {
					class: {
						name: bjname
					} = {},
					...e
				} = (this.$store.state.userInfo || {});
				return {
					...e,
					bjname
				}
			}
		},
		methods: {
			async out() {
				await this.prompt('您即将解除当前账号与当前微信的绑定关系！');
				//解绑
				this.$http.post('/api/v1/family/unBindWeChat?familyId='+this.$store.state.userInfo.familyId).then(res=>{
					return this.$store.dispatch('logout').then(res=>{
						this.prompt('提示','解绑成功！请重新从公众号进入',false).then(e=>{
							parent.WeixinJSBridge.call('closeWindow');
							uni.reLaunch({
								url:'/pages/login/login'
							})
						});
					});
				}).finally(this.$loading({msg:'解绑中'}));
			},
			async setPhoto(e){
				if(e && !(await this.prompt('该头像是用于进出学校的头像，修改请慎重。'))){
					return ;
				}
				uni.navigateTo({
					url:'./setPhoto?photo='+e
				});
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		display: flex;
		align-items: center;
		padding: 15px;
		color: #000;
		font-size: 18px;
		position: relative;

		&::after {
			content: '';
			position: absolute;
			left: 10px;
			right: 0;
			bottom: 0;
			transform: scaleY(.3);
			border-bottom: 1px solid rgba(0, 0, 0, .2);
		}

		.value {
			color: #999999;
			flex: 1;
			text-align: right;
		}
	}

	.out {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;

		.btn {
			width: 60%;
			margin: 15px auto;
			background: linear-gradient(90deg, rgba(255, 85, 127, .8) 0%, rgba(255, 0, 0, .8) 100%);
		}
	}
	.image-box{
		position: relative;
		width: 50px;
		height: 50px;
		float: right;
		border-radius: 50%;
		overflow: hidden;
		box-sizing: content-box;
		.image{
			position: absolute;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			height: 100%;
			width: 100%;
			margin: auto;
			color: #b0b0b0;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 46px;
		}
	}
</style>
